home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / vlib250.zip / VLIBDEMO.C < prev    next >
C/C++ Source or Header  |  1994-10-31  |  56KB  |  2,086 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM:    Vlibdemo.exe
  4.  
  5.     PURPOSE:    To demonstrate the usage of Visualib(TM) functions.
  6.     
  7.     PROVIDER:   Visual Tech Co.
  8.                 P.O.Box 8735
  9.                 Fort Wayne, IN 46898-8735
  10.                 Tel. (219) 289-0235
  11.                 Fax. (816) 746-6618
  12.     
  13.     DATE:               Januray. 1994
  14.  
  15. ****************************************************************************/
  16. #define    WIN32_LEAN_AND_MEAN
  17. #include <windows.h>
  18. #include <windowsx.h>
  19. #include <math.h>
  20. #include <malloc.h>
  21. #include "visualib.h"
  22. #include "vlibdemo.h"
  23. #include "demoproc.h"
  24. #include "dialogs.h"
  25.  
  26. HINSTANCE    hinst;
  27. char szAppName[] = "VlibDemo";   // The name of this application
  28. char szTitle[]   = "Visualib 2.60 Demonstration";
  29.  
  30. HVIEW   viewer21 = 0, viewer22 = 0, viewer31 = 0, viewer32 = 0,
  31.         viewer33 = 0, viewer34 = 0, viewer35 = 0;
  32. WORD    demo_function, animate_length;
  33. HLITE   light1 = 0, light2 = 0, light3 = 0,
  34.         light4 = 0, light5 = 0, light6 = 0, light7 = 0, light8 = 0;
  35. HMATE    mater1, mater2, mater3, mater4, mater5, mater6, mater7;
  36. BOOL    withframe = FALSE;
  37.  
  38. HGLOBAL        hdib1 = NULL, hdib2 = NULL, hdib3 = NULL;
  39. COLORREF    backcolor;
  40. HBRUSH        backbrush;
  41. HPALETTE    hpal;
  42.  
  43. void    FunctionDemos (HDC hdc); 
  44.  
  45. int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int nCmdShow)
  46. {
  47.     MSG        msg;
  48.  
  49.     if (hPrev)
  50.         return (FALSE);
  51.  
  52.     if (!InitApplication (hInst) || !InitInstance (hInst, nCmdShow))
  53.         return (FALSE);
  54.     
  55.     while (GetMessage (&msg, NULL, 0, 0)) {
  56.         TranslateMessage (&msg);
  57.         DispatchMessage (&msg);
  58.     }
  59.     return (msg.wParam);
  60. }
  61.  
  62. void    ViewerReset ()
  63. {
  64.     RECT    port;
  65.  
  66.     if (viewer21) {
  67.         SetRect (&port, 10, 10, 110, 110);
  68.         SetViewerFrame (viewer21, &port);
  69.         SetWindow2D (viewer21, -10, -10, 10, 10);
  70.     }
  71.  
  72.     if (viewer22) {
  73.         SetRect (&port, 10, 10, 410, 227);
  74.         SetViewerFrame (viewer22, &port);
  75.         SetWindow2D (viewer22, 0, 0, 1, (REAL) (13.0 / 24.0));
  76.     }
  77.  
  78.     if (viewer31) {
  79.         SetRect (&port, 120, 10, 220, 110);
  80.         SetViewerFrame (viewer31, &port);
  81.         SetView3D (viewer31, 100, 100, 100, 0, 0, 0, 0);
  82.         SetPerspective (viewer31, 45, 1, 1, 1000);
  83.     }
  84.  
  85.     if (viewer32) {
  86.         SetRect (&port, 230, 10, 330, 110);
  87.         SetViewerFrame (viewer32, &port);
  88.         SetView3D (viewer32, 100, 100, 100, 0, 0, 0, 0);
  89.         SetPerspective (viewer32, 45, 1, 1, 1000);
  90.     }
  91.  
  92.     if (viewer33) {
  93.         SetRect (&port, 230, 130, 330, 230);
  94.         SetViewerFrame (viewer33, &port);
  95.         SetPolarView (viewer33, 1, 1, 0, 20, 75, 45, 0);
  96.         SetPerspective (viewer33, 90, 1, 1, 1000);
  97.     }
  98.  
  99.     if (viewer34) {
  100.         SetRect (&port, 120, 130, 220, 230);
  101.         SetViewerFrame (viewer34, &port);
  102.         SetPolarView (viewer34, 0, 0, 0, 10, 45, 45, 0);
  103.         SetProjection3D (viewer34, -10, -10, 10, 10, 1, 100, VL_ORTHOGONAL);
  104.     }
  105.  
  106.     if (viewer35) {
  107.         SetRect (&port, 10, 130, 110, 230);
  108.         SetViewerFrame (viewer35, &port);
  109.         SetPolarView (viewer35, 0, 0, 0, 20, 75, 45, 0);
  110.         SetPerspective (viewer35, 90, 1, 1, 80);
  111.     }
  112. }
  113.  
  114. /****************************************************************************
  115.  
  116.     FUNCTION: InitApplication (HANDLE)
  117.  
  118. ****************************************************************************/
  119.  
  120. BOOL InitApplication (HINSTANCE hInstance)
  121. {
  122.     HDC            hdc;
  123.     WNDCLASS    wc;
  124.  
  125.     if (!InitializeVisualib ())
  126.         return (FALSE);
  127.  
  128.     hpal = SetRGBPalette ();
  129.  
  130.     SwitchLight (VL_DEFAULT, FALSE);
  131.     light1 = NewLight (VL_DISTLIGHT);
  132.     if (light1) {
  133.         LightCoordinateType (light1, VL_WORLDLIGHT);
  134.         SetLightDirection (light1, 5, 1, 4);
  135.         LightColor (light1, RGB (255, 255, 255));
  136.         SwitchLight (light1, TRUE);
  137.     }
  138.  
  139.     light2 = NewLight (VL_POINTLIGHT);
  140.     if (light2) {
  141.         SetLightLocation (light2, -50, 0, 0);
  142.         LightColor (light2, RGB (51, 255, 51));
  143.     }
  144.  
  145.     light3 = NewLight (VL_POINTLIGHT);
  146.     if (light3) {
  147.         SetLightLocation (light3, 250, -20, 0);
  148.         LightColor (light3, RGB (51, 51, 255));
  149.     }
  150.  
  151.     light4 = NewLight (VL_SPOTLIGHT);
  152.     if (light4) {
  153.         LightCoordinateType (light4, VL_WORLDLIGHT);
  154.         SetLightLocation (light4, 0, 100, 100);
  155.         SetLightDirection (light4, 0, -1, -1);
  156.         SetSpotlightSpread (light4, 20, 50);
  157.         LightColor (light4, RGB (255, 0, 0));
  158.     }
  159.  
  160.     light5 = NewLight (VL_SPOTLIGHT);
  161.     if (light5) {
  162.         LightCoordinateType (light5, VL_WORLDLIGHT);
  163.         SetLightLocation (light5, 100, 0, 100);
  164.         SetLightDirection (light5, -1, 0, -1);
  165.         SetSpotlightSpread (light5, 20, 50);
  166.         LightColor (light5, RGB (0, 255, 0));
  167.     }
  168.  
  169.     light6 = NewLight (VL_SPOTLIGHT);
  170.     if (light6) {
  171.         LightCoordinateType (light6, VL_WORLDLIGHT);
  172.         SetLightLocation (light6, 100, 100, 100);
  173.         SetLightDirection (light6, -1, -1, -1);
  174.         SetSpotlightSpread (light6, 20, 50);
  175.         LightColor (light6, RGB (0, 0, 255));
  176.     }
  177.  
  178.     light7 = NewLight (VL_POINTLIGHT);
  179.     if (light7) {
  180.         LightCoordinateType (light7, VL_WORLDLIGHT);
  181.         SetLightLocation (light7, 250, 0, 0);
  182.         LightColor (light7, RGB (255, 255, 255));
  183.     }
  184.  
  185.     light8 = NewLight (VL_POINTLIGHT);
  186.     if (light8) {
  187.         LightCoordinateType (light8, VL_WORLDLIGHT);
  188.         SetLightLocation (light8, 350, 150, 350);
  189.         LightColor (light8, RGB (255, 255, 255));
  190.     }
  191.  
  192.     hdc = GetDC (NULL);
  193.     if (GetDeviceCaps (hdc, BITSPIXEL) >= 8) {
  194.         ShadingMethod (VL_PHONGSHADE);
  195.         DepthBuffer (TRUE);
  196.     }
  197.     else {
  198.         ShadingMethod (VL_FLATSHADE);
  199.         DepthBuffer (FALSE);
  200.     }
  201.     LocalViewer (FALSE);
  202.     ReleaseDC (NULL, hdc);
  203.     
  204.     BackFaceRemoval (TRUE);
  205.  
  206.     mater1 = NewMaterial ();
  207.     MaterialSpecular (mater1, RGB (255, 255, 255));
  208.     MaterialAmbient (mater1, RGB (0, 0, 0));
  209.     MaterialDiffuse (mater1, RGB (255, 0, 0));
  210.     MaterialShininess (mater1, 50);
  211.  
  212.     mater2 = NewMaterial ();
  213.     MaterialSpecular (mater2, RGB (255, 255, 255));
  214.     MaterialAmbient (mater2, RGB (25, 25, 25));
  215.     MaterialDiffuse (mater2, RGB (0, 255, 0));
  216.     MaterialShininess (mater2, 50);
  217.  
  218.     mater3 = NewMaterial ();
  219.     MaterialSpecular (mater3, RGB (255, 255, 255));
  220.     MaterialAmbient (mater3, RGB (0, 0, 0));
  221.     MaterialDiffuse (mater3, RGB (0, 0, 255));
  222.     MaterialShininess (mater3, 50);
  223.     mater4 = NewMaterial ();
  224.     mater5 = NewMaterial ();
  225.     mater6 = NewMaterial ();
  226.     mater7 = NewMaterial ();
  227.     SelectMaterial (mater3);
  228.  
  229.     SetDepthBuffer (VL_DEFAULT);
  230.  
  231.     viewer21 = NewViewer (VL_TWOD);
  232.     viewer22 = NewViewer (VL_TWOD);
  233.     viewer31 = NewViewer (VL_THREED);
  234.     viewer32 = NewViewer (VL_THREED);
  235.     viewer33 = NewViewer (VL_THREED);
  236.     viewer34 = NewViewer (VL_THREED);
  237.     viewer35 = NewViewer (VL_THREED);
  238.  
  239.     ViewerReset ();
  240.  
  241.     demo_function = IDM_DEMO_START;
  242.     wc.style = 0;
  243.     wc.lpfnWndProc = MainWndProc;
  244.     wc.cbClsExtra = 0;
  245.     wc.cbWndExtra = 0;
  246.     wc.hInstance = hInstance;
  247.     wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (VL_LOGO));
  248.     wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  249.     backcolor = RGB (128, 128, 128);
  250.     wc.hbrBackground = GetStockObject(GRAY_BRUSH);
  251.     wc.lpszMenuName = szAppName;
  252.     wc.lpszClassName = szAppName;
  253.  
  254.     return (RegisterClass (&wc));
  255.  
  256. }
  257.  
  258. /****************************************************************************
  259.  
  260.     FUNCTION:  InitInstance (HANDLE, int)
  261.  
  262. ****************************************************************************/
  263.  
  264. BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
  265. {
  266.     HWND    hWnd;
  267.     int        sw, sh, ww, wh;
  268.  
  269.     sw = GetSystemMetrics (0);
  270.     sh = GetSystemMetrics (1);
  271.     hinst = hInstance;
  272.  
  273.     ww = (int) (sw * 0.8f);
  274.     wh = (int) (sh * 0.8f);
  275.     sw = (int) (sw / 10);
  276.     sh = (int) (sh / 10);
  277.     hWnd = CreateWindow (szAppName, szTitle,
  278.     WS_OVERLAPPEDWINDOW, sw, sh, ww, wh, NULL, NULL, hInstance, NULL);
  279.  
  280.     if (!hWnd)
  281.         return (FALSE);
  282.  
  283.     ShowWindow (hWnd, nCmdShow);
  284.     UpdateWindow (hWnd);
  285.     PostMessage (hWnd, WM_COMMAND, IDM_DEMO_WITHFRAME, 0L);
  286.     return (TRUE);
  287. }
  288.  
  289. POINT3D surf[16] = {
  290.     {-3, 0, 1}, {2, 1, 0}, {5, 0, 0}, {8, 0, 2},
  291.     {-2, 2, 3}, {1, 4, 3}, {6, 4, 1}, {7, 2, 1},
  292.     {-2, 5, 5}, {1, 7, 3}, {5, 5, 2}, {7, 6, 3},
  293.     {-2, 8, 8}, {2, 9, 0}, {4, 7, 4}, {8, 9, 9}
  294. };
  295.  
  296. REAL    sknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  297. REAL    tknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  298.  
  299. void    ObjectMotion2D (HDC hdc)
  300. {
  301.     WORD    i;
  302.     HVIEW   hv = viewer21;
  303.  
  304.     SelectViewer (hv);
  305.     if (!BeginDoubleBuffer (&hdc))
  306.         return;
  307.     PenColor (hdc, VL_RED);
  308.     for (i = 0; i < 5 * animate_length; i ++) {
  309.     CleanViewer (hdc, hv);
  310.     BrushColor (hdc, VL_GREEN);
  311.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  312.     BrushColor (hdc, VL_RED);
  313.     Star2D (hdc, 0, 0, 0, 4, 4, 5);
  314.     Rotate2D (6);
  315.         if (!UpdateDoubleBuffer (hdc))
  316.             return;
  317.     }
  318.     for (i = 0; i < 5 * animate_length; i ++) {
  319.     CleanViewer (hdc, hv);
  320.     BrushColor (hdc, VL_GREEN);
  321.     Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  322.     BrushColor (hdc, VL_RED);
  323.     Star2D (hdc, 0, 0, 0, 4, 4, 5);
  324.     MoveViewer2D (hv, 0.25f, 0, TRUE);
  325.         if (!UpdateDoubleBuffer (hdc))
  326.             return;
  327.     }
  328.  
  329.     for (i = 0; i < 5 * animate_length; i ++) {
  330.     CleanViewer (hdc, hv);
  331.     BrushColor (hdc, VL_GREEN);
  332.     Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  333.     BrushColor (hdc, VL_RED);
  334.     Star2D (hdc, 0, 0, 0, 4, 4, 5);
  335.     Scale2D ((REAL)1.06, (REAL)1.06);
  336.     if (!UpdateDoubleBuffer (hdc))
  337.             return;
  338.     }
  339.     EndDoubleBuffer (&hdc);
  340.     ViewerName (hv, "2D Object Motion");
  341. }
  342.  
  343. void    ViewerMotion3D (HDC hdc)
  344. {
  345.     WORD    i;
  346.     HVIEW   hv = viewer31;
  347.  
  348.     SelectViewer (hv);
  349.     if (!BeginDoubleBuffer (&hdc))
  350.         return;
  351.     SelectMaterial (mater1);
  352.     for (i = 0; i < 3 * animate_length; i ++) {
  353.         MoveViewer3D (hv, 0, 0, -10, TRUE);
  354.     CleanViewer (hdc, hv);
  355.         if (!Cube (hdc, 50, 50, 25))
  356.             goto exit;
  357.         UpdateDoubleBuffer (hdc);
  358.     }
  359.     SelectMaterial (mater2);
  360.     for (i = 0; i < 3 * animate_length; i ++) {
  361.     MoveViewer3D (hv, 0, 5, 0, TRUE);
  362.     CleanViewer (hdc, hv);
  363.         if (!Cube (hdc, 50, 50, 25))
  364.             goto exit;
  365.         UpdateDoubleBuffer (hdc);
  366.     }
  367.     SelectMaterial (mater3);
  368.     for (i = 0; i < 3 * animate_length; i ++) {
  369.     MoveViewer3D (hv, 5, 0, 0, TRUE);
  370.     CleanViewer (hdc, hv);
  371.         if (!Cube (hdc, 50, 50, 25))
  372.             goto exit;
  373.         UpdateDoubleBuffer (hdc);
  374.     }
  375.     SelectMaterial (VL_DEFAULT);
  376.     for (i = 0; i < 5 * animate_length; i ++) {
  377.     RotateViewer3D (hv, 6, 'z', FALSE);
  378.     CleanViewer (hdc, hv);
  379.     if (!Cube (hdc, 50, 50, 25) || !UpdateDoubleBuffer (hdc))
  380.             goto exit;
  381.     }
  382.     SelectMaterial (mater1);
  383.     for (i = 0; i < 5 * animate_length; i ++) {
  384.     CleanViewer (hdc, hv);
  385.     RotateViewer3D (hv, 6, 'y', FALSE);
  386.     if (!Cube (hdc, 50, 50, 25) || !UpdateDoubleBuffer (hdc))
  387.             goto exit;
  388.     }
  389.     SelectMaterial (mater2);
  390.     for (i = 0; i < 5 * animate_length; i ++) {
  391.     CleanViewer (hdc, hv);
  392.     RotateViewer3D (hv, 6, 'x', FALSE);
  393.         if (!Cube (hdc, 50, 50, 25) || !UpdateDoubleBuffer (hdc))
  394.             goto exit;
  395.     }
  396. exit:
  397.     EndDoubleBuffer (&hdc);
  398.     ViewerName (hv, "Viewer Motion");
  399. }
  400.  
  401. void    ObjectMotion3D (HDC hdc)
  402. {
  403.     WORD    i;
  404.     HVIEW   hv = viewer32;
  405.  
  406.     SelectViewer (hv);
  407.     if (!BeginDoubleBuffer (&hdc))
  408.         return;
  409.     SelectMaterial (mater1);
  410.     for (i = 0; i <= 5 * animate_length; i ++) {
  411.     CleanViewer (hdc, hv);
  412.         if (!Cylinder (hdc, 30, 40, 50))
  413.             break;
  414.         Rotate3D (3, 'z');
  415.         Rotate3D (6, 'x');
  416.         Rotate3D (3, 'y');
  417.         if (!UpdateDoubleBuffer (hdc))
  418.             return;
  419.     }
  420.     EndDoubleBuffer (&hdc);
  421.     ViewerName (hv, "Object Motion");
  422. }
  423.  
  424. void    ViewerZoom3D (HDC hdc)
  425. {
  426.     WORD    i;
  427.     HVIEW   hv = viewer33;
  428.     POINT3D p = {0, 0, 0};
  429.  
  430.     SelectViewer (hv);
  431.     BeginDoubleBuffer (&hdc);
  432.     SelectMaterial (mater2);
  433.     for (i = 0; i < 5 * animate_length; i ++) {
  434.     CleanViewer (hdc, hv);
  435.     if (!Cone (hdc, 3, 5, 10))
  436.             break;
  437.         ZoomViewer3D (hv, 1.05f);
  438.         UpdateDoubleBuffer (hdc);
  439.     }
  440.     EndDoubleBuffer (&hdc);
  441.     ViewerName (hv, "Viewer Zoom");
  442. }
  443.  
  444. void    RotateStar (HDC hdc)
  445. {
  446.     WORD    i;
  447.     HVIEW   hv = viewer35;
  448.  
  449.     SelectViewer (hv);
  450.     SelectMaterial (mater1);
  451.     if (!BeginDoubleBuffer (&hdc))
  452.         return;
  453.     for (i = 0; i < 5 * animate_length; i ++) {
  454.     CleanViewer (hdc, hv);
  455.         if (!SolidStar (hdc, 5, 20, 20, 5))
  456.             break;
  457.         MoveViewer3D (hv, 0, 0, -0.5f, TRUE);
  458.         Rotate3D (6 * i, 'z');
  459.         if (!UpdateDoubleBuffer (hdc))
  460.             return;
  461.     }
  462.     EndDoubleBuffer (&hdc);
  463.     ViewerName (hv, "Rotate Star");
  464. }
  465.  
  466. void    Object3D (HDC hdc)
  467. {
  468.     WORD    i;
  469.     HVIEW   hv = viewer31;
  470.  
  471.     SelectViewer (hv);
  472.     if (!BeginDoubleBuffer (&hdc))
  473.         return;
  474.     Scale3D (20, 20, 20);
  475.     for (i = 0; i < 5 * animate_length; i ++) {
  476.     CleanViewer (hdc, hv);
  477.         PenColor (hdc, VL_GREEN);
  478.     Spring (hdc, 3, 2, 0.5f);
  479.         PenColor (hdc, VL_NONE);
  480.     Translate3D (0.05f, 0, 0);
  481.     Rotate3D (-6, 'y');
  482.     PushTransformation3D (NULL);
  483.         SelectMaterial (mater3);
  484.     Rotate3D (6 * i, 'z');
  485.     Translate3D (0, 2, 0);
  486.         Rotate3D (3, 'y');
  487.         if (!Tetrahedron (hdc, 1))
  488.             break;
  489.     PushTransformation3D (NULL);
  490.         SelectMaterial (mater1);
  491.     Rotate3D (6, 'x');
  492.     Translate3D (0, 0, 2);
  493.     Rotate3D (3 * i, 'z');
  494.         if (!Octahedron (hdc, 1))
  495.             break;
  496.     PopTransformation3D (NULL);
  497.     PopTransformation3D (NULL);
  498.         if (!UpdateDoubleBuffer (hdc))
  499.             break;
  500.     }
  501.     EndDoubleBuffer (&hdc);
  502.     ViewerName (hv, "3D Curve");
  503. }
  504.  
  505. void    RotateFrame (HDC hdc)
  506. {
  507.     WORD    i;
  508.     HVIEW   hv = viewer32;
  509.     REAL   point[] = {0, 0, 0, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1,
  510.         1, -1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1,
  511.         -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1,
  512.         0, 0, 0, 1, -1, 1, -1, -1, -1, 0, 0, 0};
  513.     
  514.     SelectViewer (hv);
  515.     if (!BeginDoubleBuffer (&hdc))
  516.         return;
  517.     Scale3D (30, 30, 30);
  518.     PenColor (hdc, VL_BLUE);
  519.     for (i = 0; i < 5 * animate_length; i++) {
  520.     CleanViewer (hdc, hv);
  521.         Polyline3D (hdc, VL_3D, point, 19);
  522.     Rotate3D (6, 'z');
  523.         if (!UpdateDoubleBuffer (hdc))
  524.             break;
  525.     }
  526.     EndDoubleBuffer (&hdc);
  527.     ViewerName (hv, "Rotate Frame");
  528. }
  529.  
  530. void    RotateSurface (HDC hdc)
  531. {
  532.     WORD    i;
  533.     HVIEW   hv = viewer35;
  534.  
  535.     SelectViewer (hv);
  536.     ViewerName (hv, "NURBS Surface");
  537.     SelectMaterial (mater2);
  538.     if (!BeginDoubleBuffer (&hdc))
  539.         return;
  540.     TwoSideShading (TRUE);
  541.     for (i = 0; i < 5 * animate_length; i++) {
  542.     CleanViewer (hdc, hv);
  543.         if (!NURBSSurface (hdc, VL_3D, (VECTOR) surf, 4, 4, sknot, tknot, 8, 8))
  544.             break;
  545.     Rotate3D (6, 'z');
  546.     Rotate3D (12, 'x');
  547.     Rotate3D (3, 'y');
  548.         if (!UpdateDoubleBuffer (hdc))
  549.             break;
  550.     }
  551.     EndDoubleBuffer (&hdc);
  552. }
  553.  
  554. void    RotateDodecahedron (HDC hdc)
  555. {
  556.     WORD    i;
  557.     HVIEW   hv = viewer33;
  558.  
  559.     SelectViewer (hv);
  560.     ViewerName (hv, "Dodecahedron");
  561.     SelectMaterial (mater2);
  562.     if (!BeginDoubleBuffer (&hdc))
  563.         return;
  564.     Scale3D (6, 6, 6);
  565.     for (i = 0; i < 5 * animate_length; i ++) {
  566.     CleanViewer (hdc, hv);
  567.         if (!Dodecahedron (hdc, 0.5f))
  568.             break;
  569.     Translate3D (0, 0.1f, 0);
  570.     Rotate3D (6, 'z');
  571.         if (!UpdateDoubleBuffer (hdc))
  572.             break;
  573.     }
  574.     EndDoubleBuffer (&hdc);
  575. }
  576.  
  577. void    RotateIcosahedron (HDC hdc)
  578. {
  579.     WORD    i;
  580.     HVIEW   hv = viewer34;
  581.  
  582.     SelectViewer (hv);
  583.     ViewerName (hv, "Icosahedron");
  584.     SelectMaterial (mater1);
  585.     if (!BeginDoubleBuffer (&hdc))
  586.         return;
  587.     Scale3D (3, 3, 3);
  588.     for (i = 0; i < 5 * animate_length; i ++) {
  589.     CleanViewer (hdc, hv);
  590.         if (!Icosahedron (hdc, 1))
  591.             break;
  592.         Rotate3D (3, 'y');
  593.         Translate3D (0.1f, 0, 0);
  594.         Rotate3D (6, 'z');
  595.         if (!UpdateDoubleBuffer (hdc))
  596.             break;
  597.     }
  598.     EndDoubleBuffer (&hdc);
  599. }
  600.  
  601. void    AnimationDemo (HDC hdc, WORD cmd)
  602. {
  603.     BOOL    depthbuffer, shadingmethod, twosideshade, backfaceremoval;
  604.     BOOL    l0, l1, l2, l3;
  605.  
  606.     l0 = SwitchLight (VL_DEFAULT, FALSE);
  607.     l1 = SwitchLight (light1, FALSE);
  608.     l2 = SwitchLight (light2, FALSE);
  609.     l3 = SwitchLight (light3, FALSE);
  610.     depthbuffer = DepthBuffer (FALSE);
  611.     shadingmethod = ShadingMethod (VL_FLATSHADE);
  612.     twosideshade = TwoSideShading (FALSE);
  613.     backfaceremoval = BackFaceRemoval (TRUE);
  614.     SwitchLight (light7, TRUE);
  615.     SwitchLight (light8, TRUE);
  616.     PenColor (hdc, VL_NONE);
  617.     switch (cmd) {
  618.         case IDM_ANIMATE_FRAME:
  619.             animate_length = 10;
  620.             RotateFrame (hdc);
  621.             break;
  622.         case IDM_ANIMATE_OBJECT2D:
  623.             animate_length = 10;
  624.             ObjectMotion2D (hdc);
  625.             break;
  626.         case IDM_ANIMATE_SURFACE:
  627.             animate_length = 10;
  628.             RotateSurface (hdc);
  629.             break;
  630.         case IDM_ANIMATE_ICOSAHEDRON:
  631.             animate_length = 10;
  632.             RotateIcosahedron (hdc);
  633.             break;
  634.         case IDM_ANIMATE_OBJECT3D:
  635.             animate_length = 20;
  636.             Object3D (hdc);
  637.             break;
  638.         case IDM_ANIMATE_STAR3D:
  639.             animate_length = 15;
  640.             RotateStar (hdc);
  641.             break;
  642.         case IDM_ANIMATE_DODECAHEDRON:
  643.             animate_length = 15;
  644.             RotateDodecahedron (hdc);
  645.             break;
  646.         case IDM_ANIMATE_VIEWER3D:
  647.             animate_length = 7;
  648.             ViewerMotion3D (hdc);
  649.             break;
  650.         case IDM_ANIMATE_ZOOM3D:
  651.             animate_length = 15;
  652.             ViewerZoom3D (hdc);
  653.             break;
  654.     }
  655.     SwitchLight (light7, FALSE);
  656.     SwitchLight (light8, FALSE);
  657.     DepthBuffer (depthbuffer);
  658.     ShadingMethod (shadingmethod);
  659.     TwoSideShading (twosideshade);
  660.     BackFaceRemoval (backfaceremoval);
  661.     SwitchLight (VL_DEFAULT, l0);
  662.     SwitchLight (light1, l1);
  663.     SwitchLight (light2, l2);
  664.     SwitchLight (light3, l3);
  665. }
  666.  
  667. void CompositeDemo2D (HDC hdc)
  668. {
  669.     RECT    orgport, newport;
  670.     HVIEW   hv = viewer22;
  671.  
  672.     SelectViewer (hv);
  673.     ViewerName (hv, "Flag");
  674.     SetRect (&newport, 350, 230, 410, 260);
  675.     GetViewerFrame (hv, &orgport);
  676.     SetViewerFrame (hv, &newport);
  677.     USFlag (hdc);
  678.     TextColor (hdc, VL_BLUE, VL_NONE);
  679.     DisplayViewerName (hdc, hv, 0);
  680.     SetViewerFrame (hv, &orgport);
  681.     USFlag (hdc);
  682. }
  683.  
  684. void    Surfaces (HDC hdc, WORD cmd)
  685. {
  686.     BOOL    twosideshade;
  687.  
  688.     SelectViewer (VL_DEFAULT);
  689.     ClearDepthBuffer (0xffff);
  690.     twosideshade = TwoSideShading (TRUE);
  691.     PenColor (hdc, VL_NONE);
  692.  
  693.     PushTransformation3D (NULL);
  694.     switch (cmd) {
  695.         case IDM_SURFACE_BEZIER:
  696.         {
  697.             POINT3D surf[16] = {
  698.                 {0, 6, 3}, {2, 6, 0}, {4, 6, 2}, {6, 6, 0},
  699.                 {0, 4, 0}, {2, 4, 5}, {4, 4, 0}, {6, 4, 6},
  700.                 {0, 2, 5}, {2, 2, 0}, {4, 2, 6}, {6, 2, 0},
  701.                 {0, 0, 0}, {2, 0, 3}, {4, 0, 0}, {6, 0, 3}};
  702.  
  703.             Scale3D (5, 5, 5);
  704.             BezierSurface (hdc, VL_3D, (VECTOR) surf, 16, 16);
  705.             PenColor (hdc, VL_GREEN);
  706.             Net3D (hdc, VL_3D, (VECTOR) surf, 4, 4);
  707.             PolyMark3D (hdc, VL_3D, (VECTOR) surf, 16, 2, 2, VL_CIRCLEMARK);
  708.             ViewerName (VL_CURRENT, "Bezier Surface");
  709.             break;
  710.         }
  711.         case IDM_SURFACE_HERMIT:
  712.         {
  713.             POINT3D surf[16] = {
  714.                 {0, 0, 0}, {0, 6, 0}, {0, 6, 6}, {0, 6, -2},
  715.                 {6, 0, 0}, {6, 6, 0}, {0, 2, 2}, {0, 6, -2},
  716.                 {2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0},
  717.                 {2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0}};
  718.  
  719.             Scale3D (5, 5, 5);
  720.             HermitSurface (hdc, VL_3D, (VECTOR) surf, 16, 16);
  721.             ViewerName (VL_CURRENT, "Hermit Surface");
  722.             break;
  723.         }
  724.         case IDM_SURFACE_BSPLINE:
  725.         {
  726.             POINT3D surf[36] = {
  727.                 {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  728.                 {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  729.                 {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  730.                 {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  731.                 {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  732.                 {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  733.  
  734.             Scale3D (3, 3, 3);
  735.             BSplineSurface (hdc, VL_3D, (VECTOR) surf, 6, 6, 4, 4);
  736.             ViewerName (VL_CURRENT, "B-Spline Surface");
  737.             break;
  738.         }
  739.         case IDM_SURFACE_NURBS:
  740.         {
  741.             POINT3D surf[36] = {
  742.                 {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  743.                 {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  744.                 {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  745.                 {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  746.                 {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  747.                 {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  748.             REAL    sknot[20] = {0,0,0,1,2,3,3,3};
  749.             REAL    tknot[20] = {0,0,0,1,2,3,3,3};
  750.  
  751.             Scale3D (10, 10, 5);
  752.             Translate3D (-3, -2, 0);
  753.             NURBSSurface (hdc, VL_3D, (VECTOR) surf, 6, 6, sknot, tknot, 4, 4);
  754.             PenColor (hdc, VL_GREEN);
  755.             Net3D (hdc, VL_3D, (VECTOR) surf, 6, 6);
  756.             PolyMark3D (hdc, VL_3D, (VECTOR) surf, 36, 2, 2, VL_BOXMARK);
  757.             ViewerName (VL_CURRENT, "NURBS Surface");
  758.             break;
  759.         }
  760.         case IDM_SURFACE_COONSPATCH:
  761.         {
  762.             POINT3D point[] = {{0,0,4},{1,-2,3},{2,-2,2},{3,0,1},
  763.                                {4,0,0},{4,1,0},{4,2,0},{4,3,0},
  764.                                {4,4,0},{3,4,0},{2,4,0},{1,4,0},
  765.                                {0,4,0},{0,3,1},{-2,2,2},{-2,1,3}};
  766.             Scale3D (5, 5, 5);
  767.             CoonsPatch (hdc, VL_3D, (VECTOR) point, 5, 5);
  768.             ViewerName (VL_CURRENT, "Coons Patch Surface");
  769.             break;
  770.         }
  771.         case IDM_SURFACE_REVOLSPLINE:
  772.         {
  773.             POINT3H revcurv[10] = {
  774.                 {0.7,0.7,-7,1},{1.2,1.2,-4,1},{0.8,0.8,-2.5,1},
  775.                 {0.6,0.6,-1.5,1},{0.4,0.4,-0.5,1},{0.3,0.3,4,1},
  776.                 {0.55,0.55,4.5,1}
  777.             };
  778.  
  779.             Scale3D (10, 10, 5);
  780.             Translate3D (-3, -2, 0);
  781.             RevolveBSpline(hdc, VL_3H, (VECTOR)revcurv, 7, 12, TWOPI);
  782.             break;
  783.         }
  784.     }
  785.     PopTransformation3D (NULL);
  786.     TwoSideShading (twosideshade);
  787. }
  788.  
  789. void    PolyfacetsDemo (HDC hdc)
  790. {
  791.     WORD        i;
  792.     LPINT        vindex, nindex;
  793.     LPWIRE        wire;
  794.     LPFACET        facet;
  795.     LPVECT3        normal;
  796.     POLYFACET    polyfacet;
  797.     LPPOINT3D    vertex;
  798.  
  799.     polyfacet.nvert = 8;
  800.     polyfacet.nnorm = 4;
  801.     polyfacet.nwire = 12;
  802.     polyfacet.nfacet = 6;
  803.     polyfacet.vertex = NEWLIST (POINT3D, polyfacet.nvert);
  804.     wire = polyfacet.wire = NEWLIST (WIRE, polyfacet.nwire);
  805.     facet = polyfacet.facet = NEWLIST (FACET, polyfacet.nfacet);
  806.     normal = polyfacet.normal = NEWLIST (VECTOR3, 4);
  807.     VSET3 (normal[0], 0.6f, -0.8f, 0);
  808.     VSET3 (normal[1], 0.6f, 0.8f, 0);
  809.     VSET3 (normal[2], 0, 0.6f, 0.8f);
  810.     VSET3 (normal[3], 0, 0.6f, -0.8f);
  811.     vertex = polyfacet.vertex;
  812.     SetPoint3D (&vertex[0], 0, 0, 20);
  813.     SetPoint3D (&vertex[1], 20, 0, 20);
  814.     SetPoint3D (&vertex[2], 20, 20, 20);
  815.     SetPoint3D (&vertex[3], 0, 20, 20);
  816.     SetPoint3D (&vertex[4], 0, 0, 0);
  817.     SetPoint3D (&vertex[5], 20, 0, 0);
  818.     SetPoint3D (&vertex[6], 20, 20, 0);
  819.     SetPoint3D (&vertex[7], 0, 20, 0);
  820.     wire[3].vert2 = wire[0].vert1 = wire[4].vert1 = 0;
  821.     wire[0].vert2 = wire[1].vert1 = wire[5].vert1 = 1;
  822.     wire[1].vert2 = wire[2].vert1 = wire[6].vert1 = 2;
  823.     wire[2].vert2 = wire[3].vert1 = wire[7].vert1 = 3;
  824.     wire[11].vert2 = wire[4].vert2 = wire[8].vert1 = 4;
  825.     wire[8].vert2 = wire[5].vert2 = wire[9].vert1 = 5;
  826.     wire[9].vert2 = wire[6].vert2 = wire[10].vert1 = 6;
  827.     wire[10].vert2 = wire[7].vert2 = wire[11].vert1 = 7;
  828.     facet[0].npts = facet[1].npts = facet[2].npts = facet[3].npts = 4;
  829.     facet[4].npts = facet[5].npts = 4;
  830.     facet[0].nindex = facet[1].nindex = facet[4].nindex = facet[5].nindex = 0;
  831.     nindex = facet[2].nindex = NEWLIST (INT, 4);
  832.     VSET4 (nindex, 0, 0, 1, 1);
  833.     nindex = facet[3].nindex = NEWLIST (INT, 4);
  834.     VSET4 (nindex, 2, 3, 3, 2);
  835.     vindex = facet[0].vindex = NEWLIST (INT, 4);
  836.     VSET4 (vindex, 0, 1, 2, 3);
  837.     VSET3 (facet[0].normal, 0, 0, 1);
  838.     vindex = facet[1].vindex = NEWLIST (INT, 4);
  839.     VSET4 (vindex, 0, 4, 5, 1);
  840.     VSET3 (facet[1].normal, 0, -1, 0);
  841.     vindex = facet[2].vindex = NEWLIST (INT, 4);
  842.     VSET4 (vindex, 1, 5, 6, 2);
  843.     VSET3 (facet[2].normal, 1, 0, 0);
  844.     vindex = facet[3].vindex = NEWLIST (INT, 4);
  845.     VSET4 (vindex, 2, 6, 7, 3);
  846.     VSET3 (facet[3].normal, 0, 1, 0);
  847.     vindex = facet[4].vindex = NEWLIST (INT, 4);
  848.     VSET4 (vindex, 3, 7, 4, 0);
  849.     VSET3 (facet[4].normal, -1, 0, 0);
  850.     vindex = facet[5].vindex = NEWLIST (INT, 4);
  851.     VSET4 (vindex, 4, 7, 6, 5);
  852.     VSET3 (facet[5].normal, 0, 0, -1);
  853.  
  854.     ClearDepthBuffer (0xffff);
  855.     SelectMaterial (mater2);
  856.     SwitchLight (light7, TRUE);
  857.     SwitchLight (light8, TRUE);
  858.     ShadePolyFacet (hdc, &polyfacet);
  859.     for (i = 0; i < polyfacet.nfacet; i++) {
  860.         FREE (facet[i].vindex);
  861.         if (facet[i].nindex)
  862.             FREE (facet[i].nindex);
  863.             
  864.     }
  865.     FREE (polyfacet.vertex);
  866.     FREE (polyfacet.normal);
  867.     FREE (polyfacet.wire);
  868.     FREE (polyfacet.facet);
  869. }
  870.  
  871. VOIDED  ShowSolidPrimitives (HDC hdc, WORD cmd)
  872. {
  873.     BackFaceRemoval (TRUE);
  874.     TwoSideShading (FALSE);
  875.     ClearDepthBuffer (0xffff);
  876.     PenColor (hdc, VL_NONE);
  877.     switch (cmd) {
  878.         case IDM_SOLID_TUBE:
  879.             ViewerName (VL_CURRENT, "Tube and Ring");
  880.             Tube (hdc, 15, 20, 2, 30);
  881.             SolidRing (hdc, 40, 40, 3, 10, 115, 335, 1);
  882.             break;
  883.     case IDM_SOLID_TORUS:
  884.             ViewerName (VL_CURRENT, "Torus and Wedged Torus");
  885.             TranslateTo3D (-20, 20, 0);
  886.             if (!Torus (hdc, 15, 5))
  887.                 break;
  888.             TranslateTo3D (20, -20, 0);
  889.             WedgedTorus (hdc, 15, 5, 90, 360, 180, 90);
  890.         break;
  891.     case IDM_SOLID_SPHERE:
  892.             ViewerName (VL_CURRENT, "Sphere and Wedged Sphere");
  893.             WedgedSphere (hdc, 20, 20, 30, 90, 0, 45, 135);
  894.         break;
  895.     case IDM_SOLID_ELLIPSOID:
  896.             ViewerName (VL_CURRENT, "Ellipsoid");
  897.         Ellipsoid (hdc, 20, 40, 30);
  898.         break;
  899.     case IDM_SOLID_CYLINDER:
  900.             ViewerName (VL_CURRENT, "Cylinder and Solid Pie");
  901.             if (!WedgedCylinder (hdc, 10, 20, 30, 0.7f, 90, 0))
  902.                 break;
  903.         TranslateTo3D (30, -30, 0);
  904.         if (!SolidPie (hdc, 20, 10, 5, 45, 180))
  905.                 break;
  906.         TranslateTo3D (-30, 30, 0);
  907.         SolidPie (hdc, 20, 10, 5, 180, 45);
  908.         break;
  909.     case IDM_SOLID_CONE:
  910.             ViewerName (VL_CURRENT, "Cone and Wedged Cone");
  911.             if (!WedgedCone (hdc, 10, 20, 30, 90, 0))
  912.                 break;
  913.         TranslateTo3D (30, -30, 0);
  914.             if (!WedgedCone (hdc, 20, 10, 30, 110, 0))
  915.                 break;
  916.             TranslateTo3D (-30, 30, 0);
  917.         WedgedCone (hdc, 20, 10, 30, 180, 45);
  918.         break;
  919.     case IDM_SOLID_TETRAHEDRON:
  920.             ViewerName (VL_CURRENT, "Tetrahedron (4 facets)");
  921.         Tetrahedron (hdc, 20);
  922.         MarkPosition3D (hdc, 0, 0, 0, 10, VL_CROSSHAIR);
  923.         break;
  924.     case IDM_SOLID_OCTAHEDRON:
  925.             ViewerName (VL_CURRENT, "Octahedron (8 facets)");
  926.         Octahedron (hdc, 20);
  927.         MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  928.         break;
  929.     case IDM_SOLID_DODECAHEDRON:
  930.             ViewerName (VL_CURRENT, "Dodecahedron (12 facets)");
  931.         Dodecahedron (hdc, 20);
  932.         MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
  933.         break;
  934.     case IDM_SOLID_ICOSAHEDRON:
  935.             ViewerName (VL_CURRENT, "Icosahedron (20 facets)");
  936.         Icosahedron (hdc, 20);
  937.         MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
  938.         break;
  939.     case IDM_SOLID_FRUSTUM:
  940.             ViewerName (VL_CURRENT, "Frustum");
  941.         Frustum (hdc, 20, 30, 10, 20, 20);
  942.         break;
  943.     case IDM_SOLID_RIDGE:
  944.             ViewerName (VL_CURRENT, "Ridge");
  945.         Ridge (hdc, 20, 30, 10, 20);
  946.         break;
  947.     case IDM_SOLID_BOX:
  948.             ViewerName (VL_CURRENT, "Box");
  949.             Cube (hdc, 40, 40, 20);
  950.         break;
  951.     case IDM_SOLID_STAR:
  952.             ViewerName (VL_CURRENT, "Solid Star");
  953.         SolidStar (hdc, 5, 20, 20, 10);
  954.         break;
  955.     case IDM_SOLID_FLOWER:
  956.             ViewerName (VL_CURRENT, "Solid Flower");
  957.         SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
  958.         break;
  959.     }
  960. }
  961.  
  962. void    ShadingSettings (HWND hwnd, WORD cmd)
  963. {
  964.     COLORREF        color;
  965.  
  966.     switch (cmd) {
  967.         case IDM_OPTION_PREVIEW:
  968.         {
  969.             RECT rect = {50, 50, 100, 100};
  970.             HDC     hdc;
  971.  
  972.             SelectViewer (VL_DEFAULT);
  973.             hdc = GetDC (hwnd);
  974.             ShadingPreview (hdc, &rect, 40, 173);
  975.             ReleaseDC (hwnd, hdc);
  976.             break;
  977.         }
  978.     case IDM_GLOBAL_AMBIENT:
  979.             color = SelectColor (AmbientColor (VL_INQUIRE));
  980.             AmbientColor (color);
  981.         break;
  982. #ifndef    WIN32
  983.         case IDM_OPTION_BACKCOLOR:
  984.         {
  985.             HBRUSH  hbrush = hbrush = GetClassWord (hwnd, GCW_HBRBACKGROUND);
  986.  
  987.             backcolor = SelectColor (backcolor);
  988.             DeleteObject (hbrush);
  989.             hbrush = CreateSolidBrush (backcolor);
  990.             SetClassWord (hwnd, GCW_HBRBACKGROUND, hbrush);
  991.             InvalidateRect (hwnd, NULL, TRUE);
  992.             UpdateWindow (hwnd);
  993.             break;
  994.         }
  995. #endif
  996.         case IDM_OPTION_REDRAW:
  997.         InvalidateRect (hwnd, NULL, TRUE);
  998.             UpdateWindow (hwnd);
  999.             break;
  1000.         case IDM_OPTION_SHADEMODE:
  1001.             DialogBox (hinst, MAKEINTRESOURCE(DLGSHADING), hwnd, DlgShading);
  1002.             break;
  1003.     case IDM_SELECT_M1:
  1004.         SelectMaterial (VL_DEFAULT);
  1005.             DialogBox (hinst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
  1006.         break;
  1007.     case IDM_SELECT_M2:
  1008.         SelectMaterial (mater1);
  1009.             DialogBox (hinst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
  1010.         break;
  1011.     case IDM_SELECT_M3:
  1012.         SelectMaterial (mater2);
  1013.             DialogBox (hinst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
  1014.         break;
  1015.     case IDM_SELECT_M4:
  1016.         SelectMaterial (mater3);
  1017.             DialogBox (hinst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
  1018.         break;
  1019.     case IDM_SELECT_L1:
  1020.         SelectLight (VL_DEFAULT);
  1021.             DialogBox (hinst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
  1022.         break;
  1023.     case IDM_SELECT_L2:
  1024.         SelectLight (light1);
  1025.             DialogBox (hinst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
  1026.         break;
  1027.     case IDM_SELECT_L3:
  1028.         SelectLight (light2);
  1029.             DialogBox (hinst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
  1030.         break;
  1031.     case IDM_SELECT_L4:
  1032.         SelectLight (light3);
  1033.             DialogBox (hinst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
  1034.         break;
  1035.     case IDM_OPTION_TEXTURE:
  1036.             DialogBox (hinst, MAKEINTRESOURCE(DLGTEXTURE), hwnd, DlgTexture);
  1037.         break;
  1038.     }
  1039. }
  1040.  
  1041. WORD    halign = TA_CENTER;
  1042. WORD    valign = TA_BASELINE;
  1043.  
  1044. VOIDED  ShowTextPrimitives (HDC hdc, WORD func)
  1045. {
  1046.     char    str[40];
  1047.  
  1048.     BackFaceRemoval (TRUE);
  1049.     TwoSideShading (FALSE);
  1050.     wsprintf (str, "Visualib\nAdvanced\nTechnology");
  1051.     switch (func) {
  1052.         case IDM_TEXT_2D:
  1053.             SelectViewer (VL_DEFAULT2D);
  1054.             SetTextHeight (4);
  1055.             BrushColor (hdc, VL_RED);
  1056.             PenColor (hdc, VL_GREEN);
  1057.             SetTextAlign (hdc, halign | valign);
  1058.             Text2D (hdc, 0, 0, 0, str);
  1059.             ViewerName (VL_CURRENT, "2D Horizontal Text");
  1060.             break;
  1061.         case IDM_TEXT_3D:
  1062.             SelectViewer (VL_DEFAULT);
  1063.             MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1064.             PushTransformation3D (NULL);
  1065.             SetTextHeight (15);
  1066.             BrushColor (hdc, VL_YELLOW);
  1067.             PenColor (hdc, VL_BLUE);
  1068.             SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1069.             Text3D (hdc, 3, 1, 0, str);
  1070.             PushTransformation3D (NULL);
  1071.             Rotate3D (90, 'y');
  1072.             SetTextAlign (hdc, TA_RIGHT | TA_BOTTOM);
  1073.             Text3D (hdc, -3, 1, 0, str);
  1074.             PopTransformation3D (NULL);
  1075.             Rotate3D (-90, 'x');
  1076.             SetTextAlign (hdc, TA_TOP | TA_LEFT);
  1077.             Text3D (hdc, 3, -1, 0, str);
  1078.             PopTransformation3D (NULL);
  1079.             ViewerName (VL_CURRENT, "3D Horizontal Text");
  1080.             break;
  1081.         case IDM_TEXT_SOLID:
  1082.             SelectViewer (VL_DEFAULT);
  1083.             SetTextHeight (30);
  1084.             ClearDepthBuffer (0xffff);
  1085.             SetTextThickness (8);
  1086.             PushTransformation3D (NULL);
  1087.             Rotate3D (135, 'z');
  1088.             Rotate3D (30, 'x');
  1089.             SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
  1090.             SolidText (hdc, str);
  1091.             PopTransformation3D (NULL);
  1092.             ViewerName (VL_CURRENT, "Solid Text");
  1093.             break;
  1094.     }
  1095. }
  1096.  
  1097. void    ProcessWindowPaint (HWND hwnd)
  1098. {
  1099.     PAINTSTRUCT ps;
  1100.     HDC         hdc;
  1101.  
  1102.     hdc = BeginPaint (hwnd, &ps);
  1103.     if (hpal) {
  1104.         SelectPalette (hdc, hpal, FALSE);
  1105.         RealizePalette (hdc);
  1106.     }
  1107.     FunctionDemos (hdc);
  1108.     EndPaint (hwnd, &ps);
  1109. }
  1110.  
  1111. void    SpotlightDemo (HDC hdc)
  1112. {
  1113.     SelectViewer (VL_DEFAULT);
  1114.     ViewerName (VL_CURRENT, "Spot Lights Demo");
  1115.     ClearDepthBuffer (0xffff);
  1116.     SelectMaterial (VL_DEFAULT);
  1117.     SwitchLight (light4, TRUE);
  1118.     SwitchLight (light5, TRUE);
  1119.     SwitchLight (light6, TRUE);
  1120.     SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
  1121. }
  1122.  
  1123. void    ImageMappingDemo (HDC hdc)
  1124. {
  1125.     REAL    point[12];
  1126.     static BOOL    LoadImage = TRUE;
  1127.     char    filename[128];
  1128.  
  1129.     if (LoadImage) {
  1130.         if (GetDeviceCaps (hdc, BITSPIXEL) >= 8)
  1131.             lstrcpy (filename, "deer256.bmp");
  1132.         else
  1133.             lstrcpy (filename, "bring16.bmp");
  1134.         if (!ReadDIBFile (filename, &hdib1) && !ReadDIBFile (NULL, &hdib1))
  1135.             return;
  1136.         if (!ReadDIBFile (filename, &hdib2) && !ReadDIBFile (NULL, &hdib2))
  1137.             return;
  1138.         GetSystemDirectory (filename, 128);
  1139.         lstrcat (filename, "\\vgalogo.rle");
  1140.         if (!ReadDIBFile (filename, &hdib3) && !ReadDIBFile (NULL, &hdib3))
  1141.             return;
  1142.         LoadImage = FALSE;
  1143.     }
  1144.  
  1145.     SelectViewer (VL_DEFAULT);
  1146.     ViewerName (VL_CURRENT, "Image Mapping");
  1147.     Scale3D (20, 20, 30);
  1148.  
  1149.     point[0] = -1; point[1] = -1; point[2] = 1;
  1150.     point[3] = 1; point[4] = -1; point[5] = 1;
  1151.     point[6] = 1; point[7] = 1; point[8] = 1;
  1152.     point[9] = -1; point[10] = 1; point[11] = 1;
  1153.     if (hdib1 && !ImageMap3D (hdc, hdib1, VL_3D, point))
  1154.         return;
  1155.  
  1156.     point[0] = 1; point[1] = 1; point[2] = 1;
  1157.     point[3] = 1; point[4] = 1; point[5] = -1;
  1158.     point[6] = -1; point[7] = 1; point[8] = -1;
  1159.     point[9] = -1; point[10] = 1; point[11] = 1;
  1160.     if (hdib2 && !ImageMap3D (hdc, hdib2, VL_3D, point))
  1161.         return;
  1162.  
  1163.     point[0] = 1; point[1] = -1; point[2] = -1;
  1164.     point[3] = 1; point[4] = 1; point[5] = -1;
  1165.     point[6] = 1; point[7] = 1; point[8] = 1;
  1166.     point[9] = 1; point[10] = -1; point[11] = 1;
  1167.     if (hdib3)
  1168.         ImageMap3D (hdc, hdib3, VL_3D, point);
  1169. }
  1170.  
  1171. void    TranslateTransf2D (HDC hdc)
  1172. {
  1173.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1174.     ViewerName (VL_CURRENT, "2D Translate Transformation");
  1175.     BrushColor (hdc, VL_RED);
  1176.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1177.     Label2D (hdc, 0, 0, "Original");
  1178.     TranslateTo2D (5, 3);
  1179.     BrushColor (hdc, VL_GREEN);
  1180.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1181.     Label2D (hdc, 0, 0, "Translated To (5,3)");
  1182.     PushTransformation2D (NULL);
  1183.     Translate2D (0, -6);
  1184.     BrushColor (hdc, VL_YELLOW);
  1185.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1186.     Label2D (hdc, 0, 0, "Translated (0,-6) from above");
  1187.     PopTransformation2D (NULL);
  1188.     Translate2D (-10, 0);
  1189.     BrushColor (hdc, VL_BLUE);
  1190.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1191.     Label2D (hdc, 0, 0, "Translated (-10,0) from right");
  1192.     Translate2D (0, -6);
  1193.     BrushColor (hdc, VL_WHITE);
  1194.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1195.     Label2D (hdc, 0, 0, "Translated (0,-6) from above");
  1196. }
  1197.  
  1198. void    MirrorTransf2D (HDC hdc)
  1199. {
  1200.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1201.     ViewerName (VL_CURRENT, "2D Mirror Transformation");
  1202.     BrushColor (hdc, VL_RED);
  1203.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1204.     Label2D (hdc, 5, 3, "Original");
  1205.     PushTransformation2D (NULL);
  1206.     Mirror2D (0, 0, 0);
  1207.     BrushColor (hdc, VL_GREEN);
  1208.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1209.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with 0 degree");
  1210.     PopTransformation2D (NULL);
  1211.     PushTransformation2D (NULL);
  1212.     Mirror2D (0, 0, 90);
  1213.     BrushColor (hdc, VL_YELLOW);
  1214.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1215.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with 90 degree");
  1216.     PopTransformation2D (NULL);
  1217.     PushTransformation2D (NULL);
  1218.     Mirror2D (0, 0, (REAL)(atan2 (-5, 3) * RTOD));
  1219.     BrushColor (hdc, VL_BLUE);
  1220.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1221.     Label2D (hdc, 5, 3, "Mirrored along (0,0) with radian (-5,3)");
  1222.     PopTransformation2D (NULL);
  1223. }
  1224.  
  1225. void    StretchTransf2D (HDC hdc)
  1226. {
  1227.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1228.     ViewerName (VL_CURRENT, "2D Stretch Transformation");
  1229.     BrushColor (hdc, VL_RED);
  1230.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1231.     Label2D (hdc, 0, 0, "Original");
  1232.     PushTransformation2D (NULL);
  1233.     Stretch2D (5, 3, 0, 1.5f);
  1234.     BrushColor (hdc, VL_GREEN);
  1235.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1236.     Label2D (hdc, 5, 3, "Stretched along 0 degree");
  1237.     PopTransformation2D (NULL);
  1238.     PushTransformation2D (NULL);
  1239.     Stretch2D (5, -3, 90, 1.5f);
  1240.     BrushColor (hdc, VL_YELLOW);
  1241.     Star2D (hdc, 5, -3, 0, 2, 2, 5);
  1242.     Label2D (hdc, 5, -3, "Stretched along 90 degree");
  1243.     PopTransformation2D (NULL);
  1244.     PushTransformation2D (NULL);
  1245.     Stretch2D (-5, -3, 45, 1.5f);
  1246.     BrushColor (hdc, VL_BLUE);
  1247.     Star2D (hdc, -5, -3, 0, 2, 2, 5);
  1248.     Label2D (hdc, -5, -3, "Stretched along 45 degree");
  1249.     PopTransformation2D (NULL);
  1250.     PushTransformation2D (NULL);
  1251.     Stretch2D (-5, 3, 45, -1.5f);
  1252.     BrushColor (hdc, VL_BROWN);
  1253.     Star2D (hdc, -5, 3, 0, 2, 2, 5);
  1254.     Label2D (hdc, -5, 3, "Stretched and flipped 45 degree");
  1255.     PopTransformation2D (NULL);
  1256. }
  1257.  
  1258. void    ShearTransf2D (HDC hdc)
  1259. {
  1260.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1261.     ViewerName (VL_CURRENT, "2D Shear Transformation");
  1262.     BrushColor (hdc, VL_RED);
  1263.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1264.     Label2D (hdc, 0, 0, "Original");
  1265.     PushTransformation2D (NULL);
  1266.     Shear2D (5, 3, 0, 0.5f, 0);
  1267.     BrushColor (hdc, VL_GREEN);
  1268.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1269.     Label2D (hdc, 5, 3, "Horizontal shear");
  1270.     PopTransformation2D (NULL);
  1271.     PushTransformation2D (NULL);
  1272.     Shear2D (5, -3, 0, 0, 0.5f);
  1273.     BrushColor (hdc, VL_BLUE);
  1274.     Star2D (hdc, 5, -3, 0, 2, 2, 5);
  1275.     Label2D (hdc, 5, -3, "Vertical shear");
  1276.     PopTransformation2D (NULL);
  1277.     PushTransformation2D (NULL);
  1278.     Shear2D (-5, -3, 0, 0.5f, 0.5f);
  1279.     BrushColor (hdc, VL_YELLOW);
  1280.     Star2D (hdc, -5, -3, 0, 2, 2, 5);
  1281.     Label2D (hdc, -5, -3, "Horizontal and vertical shear");
  1282.     PopTransformation2D (NULL);
  1283.     PushTransformation2D (NULL);
  1284.     Shear2D (-5, 3, 45, 0.5f, 0);
  1285.     BrushColor (hdc, VL_BROWN);
  1286.     Star2D (hdc, -5, 3, 0, 2, 2, 5);
  1287.     Label2D (hdc, -5, 3, "Horizontal shear along 45 degree");
  1288.     PopTransformation2D (NULL);
  1289. }
  1290.  
  1291. void    PointRotateTransf2D (HDC hdc)
  1292. {
  1293.     SetTextAlign (hdc, TA_CENTER | TA_BOTTOM);
  1294.     Label2D (hdc, 5, 3, "(5,3)");
  1295.     SetTextAlign (hdc, TA_RIGHT | TA_BASELINE);
  1296.     Label2D (hdc, -5, 3, "(-5,3)");
  1297.     SetTextAlign (hdc, TA_CENTER | TA_TOP);
  1298.     Label2D (hdc, -5, -3, "(-5,-3)");
  1299.     SetTextAlign (hdc, TA_LEFT | TA_BASELINE);
  1300.     Label2D (hdc, 5, -3, "(5,-3)");
  1301.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1302.     ViewerName (VL_CURRENT, "2D Point Ratate Transformation");
  1303.     PenColor (hdc, VL_WHITE);
  1304.     BrushColor (hdc, VL_RED);
  1305.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1306.     Line2D (hdc, 5, 3, 0, 0);
  1307.     Label2D (hdc, 0, 0, "Original");
  1308.     PushTransformation2D (NULL);
  1309.     PointRotate2D (5, 3, 90);
  1310.     BrushColor (hdc, VL_GREEN);
  1311.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1312.     LineTo2D (hdc, 0, 0);
  1313.     LineTo2D (hdc, 5, 3);
  1314.     Label2D (hdc, 0, 0, "Rotate 90 degree around (5,3)");
  1315.     PopTransformation2D (NULL);
  1316.     Line2D (hdc, -5, 3, 0, 0);
  1317.     PushTransformation2D (NULL);
  1318.     PointRotate2D (-5, 3, 45);
  1319.     BrushColor (hdc, VL_YELLOW);
  1320.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1321.     LineTo2D (hdc, 0, 0);
  1322.     LineTo2D (hdc, -5, 3);
  1323.     Label2D (hdc, 0, 0, "Rotate 45 degree around (-5,3)");
  1324.     PopTransformation2D (NULL);
  1325.     Line2D (hdc, 5, -3, 0, 0);
  1326.     PushTransformation2D (NULL);
  1327.     PointRotate2D (5, -3, 45);
  1328.     BrushColor (hdc, VL_BLUE);
  1329.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1330.     LineTo2D (hdc, 0, 0);
  1331.     LineTo2D (hdc, 5, -3);
  1332.     Label2D (hdc, 0, 0, "Rotate 45 degree around (5,-3)");
  1333.     PopTransformation2D (NULL);
  1334.     Line2D (hdc, -5, -3, 0, 0);
  1335.     PushTransformation2D (NULL);
  1336.     PointRotate2D (-5, -3, 90);
  1337.     BrushColor (hdc, VL_BROWN);
  1338.     Star2D (hdc, 0, 0, 0, 2, 2, 5);
  1339.     LineTo2D (hdc, 0, 0);
  1340.     LineTo2D (hdc, -5, -3);
  1341.     Label2D (hdc, 0, 0, "Rotate 90 degree around (-5,-3)");
  1342.     PopTransformation2D (NULL);
  1343. }
  1344.  
  1345. void    PointScaleTransf2D (HDC hdc)
  1346. {
  1347.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1348.     BrushColor (hdc, VL_RED);
  1349.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1350.     Label2D (hdc, 5, 3, "Original");
  1351.     PushTransformation2D (NULL);
  1352.     PointScale2D (0, 0, -1, 1);
  1353.     BrushColor (hdc, VL_GREEN);
  1354.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1355.     Label2D (hdc, 5, 3, "Horizontal flipped");
  1356.     PopTransformation2D (NULL);
  1357.     PushTransformation2D (NULL);
  1358.     PointScale2D (0, 0, 1, -1);
  1359.     BrushColor (hdc, VL_BLUE);
  1360.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1361.     Label2D (hdc, 5, 3, "Vertical flipped");
  1362.     PopTransformation2D (NULL);
  1363.     PushTransformation2D (NULL);
  1364.     PointScale2D (0, 0, -1, -1);
  1365.     BrushColor (hdc, VL_YELLOW);
  1366.     Star2D (hdc, 5, 3, 0, 2, 2, 5);
  1367.     Label2D (hdc, 5, 3, "Horizontal and vertical flipped");
  1368.     PopTransformation2D (NULL);
  1369. }
  1370.     
  1371. void    Transformation2D (HDC hdc, WORD func)
  1372. {
  1373.     TextColor (hdc, VL_BLACK, VL_NONE);
  1374.     PushTransformation2D (NULL);
  1375.     switch (func) {
  1376.         case IDM_2DTRANSF_TRANSLATE:
  1377.             TranslateTransf2D (hdc);
  1378.             break;
  1379.         case IDM_2DTRANSF_SCALE:
  1380.             break;
  1381.         case IDM_2DTRANSF_POINTSCALE:
  1382.             PointScaleTransf2D (hdc);
  1383.             break;
  1384.         case IDM_2DTRANSF_ROTATE:
  1385.             break;
  1386.         case IDM_2DTRANSF_POINTROTATE:
  1387.             PointRotateTransf2D (hdc);
  1388.             break;
  1389.         case IDM_2DTRANSF_STRETCH:
  1390.             StretchTransf2D (hdc);
  1391.             break;
  1392.         case IDM_2DTRANSF_SHEAR:
  1393.             ShearTransf2D (hdc);
  1394.             break;
  1395.         case IDM_2DTRANSF_MIRROR:
  1396.             MirrorTransf2D (hdc);
  1397.             break;
  1398.     }
  1399.     PopTransformation2D (NULL);
  1400. }
  1401.  
  1402. void    AxleRotateTransf3D (HDC hdc)
  1403. {
  1404.     WORD    i;
  1405.     VECTOR3 ref = {0, 0, 0}, dir;
  1406.     char    str[] = "Visualib";
  1407.  
  1408.     SetTextAlign(hdc, TA_LEFT | TA_BOTTOM);
  1409.     SetTextHeight (20);
  1410.     MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  1411.     BrushColor (hdc, VL_RED);
  1412.     Text3D (hdc, 15, 15, 0, str);
  1413.     VSET3 (dir, 1, 0, 0);
  1414.     for (i = 1; i < 4; i++) {
  1415.         PushTransformation3D (NULL);
  1416.         AxleRotate3D (ref, dir, i * 90);
  1417.         BrushColor (hdc, (WORD)(i+1));
  1418.         Text3D (hdc, 15, 15, 0, str);
  1419.         PopTransformation3D (NULL);
  1420.     }
  1421.     VSET3 (dir, 0, 1, 0);
  1422.     for (i = 1; i < 4; i++) {
  1423.         PushTransformation3D (NULL);
  1424.         AxleRotate3D (ref, dir, i * 90);
  1425.         BrushColor (hdc, (WORD)(i+4));
  1426.         Text3D (hdc, 15, 15, 0, str);
  1427.         PopTransformation3D (NULL);
  1428.     }
  1429.     VSET3 (dir, 1, -1, 0);
  1430.     for (i = 1; i < 4; i++) {
  1431.         PushTransformation3D (NULL);
  1432.         AxleRotate3D (ref, dir, i * 90);
  1433.         BrushColor (hdc, (WORD)(i+7));
  1434.         Text3D (hdc, 15, 15, 0, str);
  1435.         PopTransformation3D (NULL);
  1436.     }
  1437. }
  1438.  
  1439. void    StretchTransf3D (HDC hdc)
  1440. {
  1441.     VECTOR3 ref = {0, 0, 0}, dir;
  1442.  
  1443.     SetTextHeight (30);
  1444.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1445.     PushTransformation3D (NULL);
  1446.     VSET3 (dir, -1, 1, 1);
  1447.     Stretch3D (ref, dir, 1.5f);
  1448.     Cube (hdc, 20, 20, 20);
  1449.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1450.     PopTransformation3D (NULL);
  1451. }
  1452.  
  1453. void    ShearTransf3D (HDC hdc)
  1454. {
  1455.     VECTOR3 origin = {0, 0, 0}, normal = {0, 0, 1};
  1456.  
  1457.     SetTextHeight (30);
  1458.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1459.     PushTransformation3D (NULL);
  1460.     Shear3D (origin, normal, -0.5f, 0.5f);
  1461.     Cube (hdc, 20, 20, 20);
  1462.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1463.     PopTransformation3D (NULL);
  1464. }
  1465.  
  1466. void    MirrorTransf3D (HDC hdc)
  1467. {
  1468.     VECTOR3 ref = {0, 0, 0}, dir;
  1469.     char    str[] = "Visualib";
  1470.  
  1471.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1472.     ViewerName (VL_CURRENT, "3D Mirror Transformation");
  1473.     SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1474.     SetTextHeight (20);
  1475.     BrushColor (hdc, VL_RED);
  1476.     Text3D (hdc, 3, 3, 0, str);
  1477.     PushTransformation3D (NULL);
  1478.     VSET3 (dir, 1, 0, 0);
  1479.     Mirror3D (ref, dir);
  1480.     BrushColor (hdc, VL_GREEN);
  1481.     Text3D (hdc, 3, 3, 0, str);
  1482.     PopTransformation3D (NULL);
  1483.     PushTransformation3D (NULL);
  1484.     VSET3 (dir, 0, 1, 0);
  1485.     Mirror3D (ref, dir);
  1486.     BrushColor (hdc, VL_YELLOW);
  1487.     Text3D (hdc, 3, 3, 0, str);
  1488.     PopTransformation3D (NULL);
  1489.     PushTransformation3D (NULL);
  1490.     VSET3 (dir, -1, -1, 0);
  1491.     Mirror3D (ref, dir);
  1492.     BrushColor (hdc, VL_BLUE);
  1493.     Text3D (hdc, 3, 3, 0, str);
  1494.     PopTransformation3D (NULL);
  1495. }
  1496.  
  1497. void    PointScaleTransf3D (HDC hdc)
  1498. {
  1499.     char    str[] = "Visualib";
  1500.  
  1501.     MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1502.     ViewerName (VL_CURRENT, "3D PointScale Transformation");
  1503.     SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1504.     SetTextHeight (20);
  1505.     BrushColor (hdc, VL_RED);
  1506.     Text3D (hdc, 3, 3, 0, str);
  1507.     PushTransformation3D (NULL);
  1508.     PointScale3D (0, 0, 0, -1, 1, 1);
  1509.     BrushColor (hdc, VL_GREEN);
  1510.     Text3D (hdc, 3, 3, 0, str);
  1511.     PopTransformation3D (NULL);
  1512.     PushTransformation3D (NULL);
  1513.     PointScale3D (0, 0, 0, 1, -1, 1);
  1514.     BrushColor (hdc, VL_YELLOW);
  1515.     Text3D (hdc, 3, 3, 0, str);
  1516.     PopTransformation3D (NULL);
  1517.     PushTransformation3D (NULL);
  1518.     PointScale3D (0, 0, 0, -1, -1, 1);
  1519.     BrushColor (hdc, VL_BLUE);
  1520.     Text3D (hdc, 3, 3, 0, str);
  1521.     PopTransformation3D (NULL);
  1522. }
  1523.  
  1524. void    Transformation3D (HDC hdc, int func)
  1525. {
  1526.     TextColor (hdc, VL_WHITE, VL_NONE);
  1527.     ClearDepthBuffer (0xffff);
  1528.     switch (func) {
  1529.         case IDM_3DTRANSF_TRANSLATE:
  1530.             break;
  1531.         case IDM_3DTRANSF_SCALE:
  1532.             break;
  1533.         case IDM_3DTRANSF_POINTSCALE:
  1534.             PointScaleTransf3D (hdc);
  1535.             break;
  1536.         case IDM_3DTRANSF_ROTATE:
  1537.             break;
  1538.         case IDM_3DTRANSF_AXLEROTATE:
  1539.             AxleRotateTransf3D (hdc);
  1540.             break;
  1541.         case IDM_3DTRANSF_STRETCH:
  1542.             StretchTransf3D (hdc);
  1543.             break;
  1544.         case IDM_3DTRANSF_SHEAR:
  1545.             ShearTransf3D (hdc);
  1546.             break;
  1547.         case IDM_3DTRANSF_MIRROR:
  1548.             MirrorTransf3D (hdc);
  1549.             break;
  1550.     }
  1551. }
  1552.  
  1553. VOIDED  MaterialPropertyDemo (HDC hdc)
  1554. {
  1555.     WORD    i, j, n = 1, shininess;
  1556.     REAL    ks, kd;
  1557.     RECT    rect;
  1558.     HMATE           hm = SelectMaterial (VL_CURRENT);
  1559.     COLORREF        diffuse, specular;
  1560.  
  1561.     SwitchLight (light7, TRUE);
  1562.     SwitchLight (light8, TRUE);
  1563.     SelectViewer (VL_DEFAULT);
  1564.     ViewerName (VL_CURRENT, "Material Reflection Property");
  1565.     specular = MaterialSpecular (hm, VL_INQUIRE);
  1566.     diffuse = MaterialDiffuse (hm, VL_INQUIRE);
  1567.     shininess = MaterialShininess (hm, VL_INQUIRE);
  1568.     rect.top = 10;
  1569.     ks = 0.1f;
  1570.     for (i = 0; i < 6; i++) {
  1571.         kd = 0.05f;
  1572.         rect.left = 10;
  1573.         rect.bottom = rect.top + 40;
  1574.         for (j = 0; j < 10; j++) {
  1575.             rect.right = rect.left + 40;
  1576.             MaterialShininess (hm, n);
  1577.             MaterialSpecular (hm, ScaleColor (specular, ks));
  1578.             MaterialDiffuse (VL_CURRENT, ScaleColor (diffuse, kd));
  1579.             if (!ShadingPreview (hdc, &rect, 5, 173))
  1580.                 goto exit;
  1581.             rect.left += 49;
  1582.             kd += 0.1f;
  1583.         }
  1584.         ks += 0.2f;
  1585.         rect.top += 53;
  1586.         n *= 2;
  1587.     }
  1588. exit:
  1589.     MaterialDiffuse (hm, diffuse);
  1590.     MaterialSpecular (hm, specular);
  1591.     MaterialShininess (hm, shininess);
  1592. }
  1593.  
  1594. void    CompositeDemo3D (HDC hdc)
  1595. {
  1596.     REAL    r0, r1, r2, t1, t2, h;
  1597.     WORD    i;
  1598.     BOOL    flag;
  1599.  
  1600.     SelectViewer (VL_DEFAULT);
  1601.     ViewerName (VL_DEFAULT, "Object Composition");
  1602.     ClearDepthBuffer (0xffff);
  1603.     SwitchLight (light7, TRUE);
  1604.     SwitchLight (light8, TRUE);
  1605.     SelectMaterial (VL_DEFAULT);
  1606.     PushTransformation3D (NULL);
  1607.     r0 = 4; r1 = 30; r2 = 40;
  1608.     t1 = 3; t2 = 2; h = 10;
  1609.  
  1610.     if (!SolidRing (hdc, r2, r2, t2, h, 115, 335, 1))
  1611.         goto exit;
  1612.  
  1613.     PushTransformation3D (NULL);
  1614.     Translate3D (0, 0, h / 2);
  1615.     SelectMaterial (mater1);
  1616.     Rotate3D (135, 'z');
  1617.     for (i = 0; i < 10; i++) {
  1618.         PushTransformation3D (NULL);
  1619.         Translate3D (35, 0, 0);
  1620.         flag = Sphere (hdc, r0);
  1621.         PopTransformation3D (NULL);
  1622.         Rotate3D (20, 'z');
  1623.         if (!flag)
  1624.             goto exit;
  1625.     }
  1626.     PopTransformation3D (NULL);
  1627.     SelectMaterial (VL_DEFAULT);
  1628.     if (!Tube (hdc, r1, r1, t1, h))
  1629.         goto exit;
  1630.     PushTransformation3D (NULL);
  1631.     Translate3D (0, 0, h / 2);
  1632.     SelectMaterial (mater1);
  1633.     Rotate3D (-25, 'z');
  1634.     for (i = 0; i < 8; i++) {
  1635.         PushTransformation3D (NULL);
  1636.         Translate3D (35, 0, 0);
  1637.         flag = Sphere (hdc, r0);
  1638.         PopTransformation3D (NULL);
  1639.         Rotate3D (20, 'z');
  1640.         if (!flag)
  1641.             break;
  1642.     }
  1643.     PopTransformation3D (NULL);
  1644. exit:
  1645.     PopTransformation3D (NULL);
  1646. }
  1647.  
  1648. void    DepthClippingDemo (HDC hdc)
  1649. {
  1650.     HVIEW   hv = VL_DEFAULT;
  1651.  
  1652.     SelectViewer (hv);
  1653.     SetPerspective (hv, 45, 1, 141, 200);
  1654.     ClearDepthBuffer (0xffff);
  1655.     SwitchLight (light7, TRUE);
  1656.     SwitchLight (light8, TRUE);
  1657.     SelectMaterial (mater1);
  1658.     TranslateTo3D (20, 0, 0);
  1659.     if (!Sphere (hdc, 20))
  1660.         goto exit;
  1661.     SelectMaterial (mater2);
  1662.     TranslateTo3D (0, 20, 0);
  1663.     if (!Sphere (hdc, 20))
  1664.         goto exit;
  1665.     SelectMaterial (mater3);
  1666.     TranslateTo3D (0, 0, 20);
  1667.     if (!Sphere (hdc, 20))
  1668.         goto exit;
  1669.     TranslateTo3D (0, 0, 0);
  1670.     SelectMaterial (VL_DEFAULT);
  1671.     Cube (hdc, 40, 40, 40);
  1672. exit:
  1673.     SetPerspective (hv, 45, 1, 30, 1000);
  1674.     ViewerName (hv, "Depth Buffer and Clipping");
  1675. }
  1676.  
  1677. void    MarbleRingDemo (HDC hdc)
  1678. {
  1679.     WORD    texture;
  1680.  
  1681.     SelectViewer (VL_DEFAULT);
  1682.     ViewerName (VL_CURRENT, "Marble Ring");
  1683.     ClearDepthBuffer (0xffff);
  1684.     SelectMaterial (mater3);
  1685.     texture = SolidTexture (VL_MARBLE);
  1686.     MaterialSpecular (mater3, RGB (255, 255, 255));
  1687.     SwitchLight (light7, TRUE);
  1688.     SwitchLight (light8, TRUE);
  1689.     Torus (hdc, 35, 5);
  1690.     SolidTexture (texture);
  1691. }
  1692.  
  1693. void    WoodSurfaceDemo (HDC hdc)
  1694. {
  1695.     WORD    texture;
  1696.     
  1697.     POINT3D surf[36] = {
  1698.         {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  1699.         {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  1700.         {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  1701.         {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  1702.         {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  1703.         {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  1704.     REAL    sknot[20] = {0,0,0,1,2,3,3,3};
  1705.     REAL    tknot[20] = {0,0,0,1,2,3,3,3};
  1706.  
  1707.     SelectViewer (VL_DEFAULT);
  1708.     ViewerName (VL_CURRENT, "Wood Surface");
  1709.     ClearDepthBuffer (0xffff);
  1710.     texture = SolidTexture (VL_WOODGRAIN);
  1711.     SwitchLight (light7, TRUE);
  1712.     SwitchLight (light8, TRUE);
  1713.     Translate3D (-15, -15, 5);
  1714.     Scale3D (10, 10, 5);
  1715.     NURBSSurface (hdc, VL_3D, (VECTOR) surf, 6, 6, sknot, tknot, 4, 4);
  1716.     SolidTexture (texture);
  1717. }
  1718.  
  1719. void    GraniteCubeDemo (HDC hdc)
  1720. {
  1721.     WORD    texture;
  1722.     WORD    l8;
  1723.  
  1724.     SelectViewer (VL_DEFAULT);
  1725.     ViewerName (VL_CURRENT, "Granite Cube");
  1726.     ClearDepthBuffer (0xffff);
  1727.     texture = SolidTexture (VL_GRANITE);
  1728.     SelectMaterial (VL_DEFAULT);
  1729.     l8 = LightIntensity (light8, 2);
  1730.     SwitchLight (light7, TRUE);
  1731.     SwitchLight (light8, TRUE);
  1732.     Cube (hdc, 30, 30, 30);
  1733.     SolidTexture (texture);
  1734.     LightIntensity (light8, l8);
  1735. }
  1736.  
  1737. void    StereoTextDemo (HDC hdc)
  1738. {
  1739.     SelectViewer (VL_DEFAULT);
  1740.     SelectMaterial (mater3);
  1741.     ClearDepthBuffer (0xffff);
  1742.     SetTextHeight (40);
  1743.     SetTextThickness (8);
  1744.     SwitchLight (light4, TRUE);
  1745.     SwitchLight (light7, TRUE);
  1746.     SelectMaterial (VL_DEFAULT);
  1747.     PushTransformation3D (NULL);
  1748.     Rotate3D (135, 'z');
  1749.     Rotate3D (90, 'x');
  1750.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1751.     SolidText (hdc, "Visualib");
  1752.     PopTransformation3D (NULL);
  1753.     ViewerName (VL_CURRENT, "Stereo Text");
  1754. }
  1755.  
  1756. void    Welcome (HDC hdc)
  1757. {
  1758.     char    str[80];
  1759.  
  1760.     SelectViewer (VL_DEFAULT2D);
  1761.     SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
  1762.     SetTextHeight (4);
  1763.     PenColor (hdc, VL_RED);
  1764.     BrushColor (hdc, VL_YELLOW);
  1765.     wsprintf (str, "Welcome\nto\nVisuaLib");
  1766.     SetFont (NULL);
  1767.     Text2D (hdc, 0, 0, 0, str);
  1768. }
  1769.  
  1770. void    BumpyDonutDemo (HDC hdc)
  1771. {
  1772.     WORD    texture;
  1773.  
  1774.     SelectViewer (VL_DEFAULT);
  1775.     ViewerName (VL_CURRENT, "Bumpy Donut");
  1776.     SelectMaterial (mater2);
  1777.     ClearDepthBuffer (0xffff);
  1778.     texture = SolidTexture (VL_BUMPY);
  1779.     MaterialSpecular (mater2, RGB (255, 255, 255));
  1780. //      SwitchLight (light7, TRUE);
  1781.     SwitchLight (light8, TRUE);
  1782.     Torus (hdc, 35, 10);
  1783.     SolidTexture (texture);
  1784. }
  1785.  
  1786. void    VlibDemo (HDC hdc, WORD func)
  1787. {
  1788.     BOOL    l0, l1, l2, l3;
  1789.     BOOL    twosideshade, backfaceoff;
  1790.  
  1791.     l0 = SwitchLight (VL_DEFAULT, FALSE);
  1792.     l1 = SwitchLight (light1, FALSE);
  1793.     l2 = SwitchLight (light2, FALSE);
  1794.     l3 = SwitchLight (light3, FALSE);
  1795.     twosideshade = TwoSideShading (FALSE);
  1796.     backfaceoff = BackFaceRemoval (TRUE);
  1797.     switch (func) {
  1798.         case IDM_DEMO_START:
  1799.             Welcome (hdc);
  1800.             break;
  1801.         case IDM_DEMO_SPOTLIGHT:
  1802.             SpotlightDemo (hdc);
  1803.             break;
  1804.         case IDM_DEMO_MATERIALPROPERTY:
  1805.             MaterialPropertyDemo (hdc);
  1806.             break;
  1807.         case IDM_DEMO_IMAGEMAPPING:
  1808.             ImageMappingDemo (hdc);
  1809.             break;
  1810.         case IDM_DEMO_DEPTHCLIPPING:
  1811.             DepthClippingDemo (hdc);
  1812.             break;
  1813.         case IDM_DEMO_MARBLERING:
  1814.             MarbleRingDemo (hdc);
  1815.             break;
  1816.         case IDM_DEMO_BUMPYDONUT:
  1817.             BumpyDonutDemo (hdc);
  1818.             break;
  1819.         case IDM_DEMO_GRANITECUBE:
  1820.             GraniteCubeDemo (hdc);
  1821.             break;
  1822.         case IDM_DEMO_WOODSURFACE:
  1823.             WoodSurfaceDemo (hdc);
  1824.             break;
  1825.         case IDM_DEMO_3DCOMPOSITE:
  1826.             CompositeDemo3D (hdc);
  1827.             break;
  1828.         case IDM_DEMO_STEREOTEXT:
  1829.             StereoTextDemo (hdc);
  1830.             break;
  1831.         case IDM_DEMO_2DCOMPOSITE:
  1832.             CompositeDemo2D (hdc);
  1833.             break;
  1834.         case IDM_DEMO_NURBSCURVE:
  1835.             SelectViewer (VL_DEFAULT2D);
  1836.             Primitives2D (hdc, IDM_2DCURVE_NURBS);
  1837.             SelectViewer (VL_DEFAULT);
  1838.             Primitives3D (hdc, IDM_3DCURVE_NURBS);
  1839.             break;
  1840.         case IDM_DEMO_POLYFACET:
  1841.             SelectViewer (VL_DEFAULT);
  1842.             ViewerName (VL_CURRENT, "Poly Facets");
  1843.             PolyfacetsDemo (hdc);
  1844.             break;
  1845.     }
  1846.     TwoSideShading (twosideshade);
  1847.     BackFaceRemoval (backfaceoff);
  1848.     SwitchLight (VL_DEFAULT, l0);
  1849.     SwitchLight (light1, l1);
  1850.     SwitchLight (light2, l2);
  1851.     SwitchLight (light3, l3);
  1852.     SwitchLight (light4, FALSE);
  1853.     SwitchLight (light5, FALSE);
  1854.     SwitchLight (light6, FALSE);
  1855.     SwitchLight (light7, FALSE);
  1856.     SwitchLight (light8, FALSE);
  1857.     SelectMaterial (mater3);
  1858. }
  1859.  
  1860. void    FunctionDemos (HDC hdc)
  1861. {
  1862.     WORD    func = demo_function;
  1863.  
  1864.     SetROP2 (hdc, R2_COPYPEN);
  1865.     if (func > IDM_2DPRIME_START && func < IDM_2DPRIME_END) {
  1866.         SelectViewer (VL_DEFAULT2D);
  1867.         Prime2D (hdc, func);
  1868.     }
  1869.     else if (func > IDM_3DPRIME_START && func < IDM_3DPRIME_END) {
  1870.         SelectViewer (VL_DEFAULT);
  1871.         Prime3D (hdc, func);
  1872.     }
  1873.     else if (func >= IDM_SURFACE_START && func < IDM_SURFACE_END) {
  1874.         SelectViewer (VL_DEFAULT);
  1875.         Surfaces (hdc, func);
  1876.     }
  1877.     else if (func >= IDM_SOLID_START && func < IDM_SOLID_END) {
  1878.         SelectViewer (VL_DEFAULT);
  1879.         ShowSolidPrimitives (hdc, func);
  1880.     }
  1881.     else if (func > IDM_ANIMATE_START && func < IDM_ANIMATE_END) {
  1882.         AnimationDemo (hdc, func);
  1883.         ViewerReset ();
  1884.         SelectMaterial (mater3);
  1885.     }
  1886.     else if (func > IDM_TEXT_START && func < IDM_TEXT_END) {
  1887.         ShowTextPrimitives (hdc, func);
  1888.     }
  1889.     else if (func > IDM_2DTRANSF_BEGIN && func < IDM_3DTRANSF_BEGIN) {
  1890.         SelectViewer (VL_DEFAULT2D);
  1891.         Transformation2D (hdc, func);
  1892.     }
  1893.     else if (func > IDM_3DTRANSF_BEGIN && func < IDM_3DTRANSF_END) {
  1894.         SelectViewer (VL_DEFAULT);
  1895.         Transformation3D (hdc, func);
  1896.     }
  1897.     else if (func > IDM_2DPRIMIT_START && func < IDM_2DPRIMIT_END) {
  1898.         SelectViewer (VL_DEFAULT2D);
  1899.         Primitives2D (hdc, func);
  1900.     }
  1901.     else if (func > IDM_3DPRIMIT_START && func < IDM_3DPRIMIT_END) {
  1902.         SelectViewer (VL_DEFAULT);
  1903.         Primitives3D (hdc, func);
  1904.     }
  1905.     else if (func > IDM_3DARRAY_BEGIN && func < IDM_3DARRAY_END) {
  1906.         SelectViewer (VL_DEFAULT);
  1907.         ObjectArray3D (hdc, func);
  1908.     }
  1909.     else if (func > IDM_2DARRAY_BEGIN && func < IDM_2DARRAY_END) {
  1910.         SelectViewer (VL_DEFAULT2D);
  1911.         ObjectArray2D (hdc, func);
  1912.     }
  1913.     else if (func / 100 == 20) {
  1914.         SelectViewer (VL_DEFAULT);
  1915.         ModellibDemo (hdc, func);
  1916.     }
  1917.     else {
  1918.         VlibDemo (hdc, func);
  1919.     }
  1920.     PenColor (hdc, VL_BLUE);
  1921.     DisplayViewerFrame (hdc, VL_CURRENT);
  1922.     TextColor (hdc, VL_RED, VL_NONE);
  1923.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1924. }
  1925.  
  1926. void    AdjustViewer (HWND hwnd, HVIEW hv)
  1927. {
  1928.     RECT    rect;
  1929.  
  1930.     GetClientRect (hwnd, &rect);
  1931.     rect.left += 10;
  1932.     rect.right -= 10;
  1933.     rect.top += 10;
  1934.     rect.bottom -= 20;
  1935.     SetViewerFrame (hv, &rect);
  1936. }
  1937.  
  1938. BOOLEAN SavePicture (HWND hwnd, BOOL withframe)
  1939. {
  1940.     RECT    rect;
  1941.     HANDLE  hdib;
  1942.     BOOL    flag;
  1943.  
  1944.     GetScreenRect (hwnd, withframe, &rect);
  1945.     hdib = ScreenToDIB (&rect);
  1946.     if (!hdib)
  1947.         return (FALSE);
  1948.     flag = WriteDIBFile (NULL, hdib);
  1949.     GlobalUnlock (hdib);
  1950.     GlobalFree (hdib);
  1951.     return (flag);
  1952. }
  1953.  
  1954. BOOLEAN PrintPicture (HWND hwnd, BOOL withframe)
  1955. {
  1956.     RECT    rect;
  1957.     HANDLE  hdib;
  1958.     BOOL    flag;
  1959.  
  1960.     GetScreenRect (hwnd, withframe, &rect);
  1961.     hdib = ScreenToDIB (&rect);
  1962.     if (!hdib)
  1963.         return (FALSE);
  1964.     flag = PrintImage (hdib,
  1965.         VL_BESTFIT | VL_VERTCENTER | VL_HORZCENTER | VL_MARKCORNER,
  1966.         0, 0, 0, 0);
  1967.     GlobalUnlock (hdib);
  1968.     GlobalFree (hdib);
  1969.     return (flag);
  1970. }
  1971.  
  1972. void    PrintFlag (void)
  1973. {
  1974.     SelectViewer (viewer22);
  1975.     PrintDrawing (USFlag,
  1976.         VL_BESTFIT | VL_HORZCENTER | VL_VERTCENTER | VL_MARKCORNER,
  1977.         0, 0, 0, 0);
  1978. }
  1979.  
  1980. void    ExitVlibDemo (HWND hwnd)
  1981. {
  1982. #ifndef    WIN32
  1983.     DeleteObject (GetClassWord (hwnd, GCW_HBRBACKGROUND));
  1984. #endif
  1985.     ExitVisualib ();
  1986.     if (hdib1) {
  1987.         GlobalUnlock (hdib1);
  1988.         GlobalFree (hdib1);
  1989.     }
  1990.     if (hdib2) {
  1991.         GlobalUnlock (hdib2);
  1992.         GlobalFree (hdib2);
  1993.     }
  1994.     if (hdib3) {
  1995.         GlobalUnlock (hdib3);
  1996.         GlobalFree (hdib3);
  1997.     }
  1998.     PostQuitMessage (0);
  1999. }
  2000.  
  2001. void    AlterMenuItem (HWND hwnd, WORD entry)
  2002. {
  2003.     WORD    flag = MF_BYCOMMAND;
  2004.  
  2005.     switch (entry) {
  2006.         case IDM_DEMO_WITHFRAME:
  2007.             withframe = !withframe;
  2008.             flag |= (withframe) ? MF_CHECKED : MF_UNCHECKED;
  2009.             break;
  2010.     }
  2011.     CheckMenuItem (GetMenu (hwnd), entry, flag);
  2012. }
  2013.                         
  2014. /****************************************************************************
  2015.  
  2016.     FUNCTION: MainWndProc (HWND, WORD, WORD, LONG)
  2017.  
  2018. ****************************************************************************/
  2019.  
  2020. long WINAPI MainWndProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
  2021. {
  2022.     switch (msg) {
  2023.     case WM_COMMAND:
  2024.         switch (wparam) {
  2025.         case IDM_DEMO_EXIT:
  2026.             PostMessage (hwnd, WM_DESTROY, 0, 0L);
  2027.             break;
  2028.         case IDM_HELP_ABOUT:
  2029.             AboutVisualib ();
  2030.             SendMessage (hwnd, WM_COMMAND, IDM_DEMO_START, 0L);
  2031.             break;
  2032.         case IDM_HELP_LICENSE:
  2033.             LicenseInfo ();
  2034.             break;
  2035.         case IDM_HELP_DEMOPROG:
  2036.             WinHelp (hwnd, "vlibdemo.hlp", HELP_INDEX, 0);
  2037.             break;
  2038.         case IDM_HELP_VISUALIB:
  2039.             WinHelp (hwnd, "visualib.hlp", HELP_INDEX, 0);
  2040.             break;
  2041.         case IDM_DEMO_SAVEPICTURE:
  2042.             SavePicture (hwnd, withframe);
  2043.             break;
  2044.         case IDM_DEMO_PRINTPICTURE:
  2045.             PrintPicture (hwnd, withframe);
  2046.             break;
  2047.         case IDM_DEMO_WITHFRAME:
  2048.             AlterMenuItem (hwnd, (WORD)wparam);
  2049.             break;
  2050.         case IDM_DEMO_PRINTFLAG:
  2051.             PrintFlag ();
  2052.             break;
  2053.         case IDM_TEXT_SELECTFONT:
  2054.             SelectTrueTypeFont ();
  2055.             return (0);
  2056.         default:
  2057.             if (wparam > 200 && wparam < 300) {
  2058.                 ShadingSettings (hwnd, (WORD)wparam);
  2059.             }
  2060.             else {
  2061.                 demo_function = wparam;
  2062.                 InvalidateRect (hwnd, NULL, TRUE);
  2063.                 return (DefWindowProc (hwnd, msg, wparam, lparam));
  2064.             }
  2065.         }
  2066.         break;
  2067.     case WM_DESTROY:
  2068.         ExitVlibDemo (hwnd);
  2069.         break;
  2070.  
  2071.     case WM_PAINT:
  2072.         ProcessWindowPaint (hwnd);
  2073.         break;
  2074.     
  2075.     case WM_SIZE:
  2076.         AdjustViewer (hwnd, VL_DEFAULT2D);
  2077.         AdjustViewer (hwnd, VL_DEFAULT);
  2078.         InvalidateRect (hwnd, NULL, TRUE);
  2079.         break;
  2080.  
  2081.     default:
  2082.         return (DefWindowProc (hwnd, msg, wparam, lparam));
  2083.     }
  2084.     return (0);
  2085. }
  2086.